{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Run Voicevox using Google Colab's GPU\n",
        "\n",
        "To enable GPU in this notebook, select Runtime -> Change runtime type in the Menu bar. Under Hardware Accelerator, select GPU.\n",
        "\n",
        "To run Voicevox, select Runtime -> Run all. Go to this [cell](#scrollTo=rfvusCdM2HwL&line=6&uniqifier=1) and read the instructions on how to update your `.env` file to use Voicevox running in this notebook."
      ],
      "metadata": {
        "id": "Y95LvKkhYmsF"
      }
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LwKDmIISYpJN"
      },
      "source": [
        "## Download Voicevox Engine (Linux GPU version)\n",
        "\n",
        "Update ENGINE_VER to the latest version if needed from [here](https://github.com/VOICEVOX/voicevox_engine/releases)."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "nAOSarJw8CyQ"
      },
      "outputs": [],
      "source": [
        "ENGINE_VER = '0.14.2'\n",
        "ZIP_FILENAME = f'voicevox_engine-linux-nvidia-{ENGINE_VER}.7z.001'\n",
        "DOWNLOAD_LINK = f'https://github.com/VOICEVOX/voicevox_engine/releases/download/{ENGINE_VER}/{ZIP_FILENAME}'"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "KqxleuB1gehz"
      },
      "outputs": [],
      "source": [
        "!wget $DOWNLOAD_LINK -q\n",
        "!7z x $ZIP_FILENAME\n",
        "!rm $ZIP_FILENAME"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "IzXXPHS1hJsi"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/VOICEVOX/voicevox_engine -q"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Dependencies\n",
        "\n",
        "Requirements.txt file has python version requirements, `sed \"s/;.*//\" requirements.txt` ignores this and forces the pip install since google colab is using a higher python version."
      ],
      "metadata": {
        "id": "59yjBHJxV_Oe"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "n-kGmM71SSu3"
      },
      "outputs": [],
      "source": [
        "!npm install -g localtunnel -q\n",
        "!pip install -r <(sed \"s/;.*//\" voicevox_engine/requirements.txt) -q\n",
        "!pip install numpy==1.22 -q"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Run with GPU\n",
        "\n",
        "After running, copy the public url from the localtunnel output in the cell below and update VOICEVOX_BASE_URL in your `.env` file.\n",
        "\n",
        "```\n",
        "VOICEVOX_BASE_URL=<PUBLIC_URL>\n",
        "```\n",
        "\n",
        "This url will change every time you rerun this cell, so remember to update your .env file when that happens."
      ],
      "metadata": {
        "id": "rfvusCdM2HwL"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "sf3d431fKXoL"
      },
      "outputs": [],
      "source": [
        "!python voicevox_engine/run.py --voicevox_dir='linux-nvidia' --use_gpu --allow_origin * --cors_policy_mode all > /dev/null 2>&1 & lt --port 50021"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "gpuClass": "standard",
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "nbformat": 4,
  "nbformat_minor": 0
}